package com.ygswglxt.leave.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ygswglxt.leave.entity.LeaveRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface LeaveMapper extends BaseMapper<LeaveRecord> {
    
    /**
     * 获取待审批的请假申请（联表查询员工名称）
     */
    @Select("SELECT lr.*, COALESCE(u.name, u.username) as userName " +
            "FROM leave_record lr " +
            "LEFT JOIN sys_user u ON lr.user_id = u.id " +
            "WHERE lr.status = 'PENDING' " +
            "ORDER BY lr.create_time DESC")
    List<LeaveRecord> selectPendingLeavesWithUserName();
}

